<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ManagerAviso
 *
 * @author jhonny
 */
class ManagerAviso extends ManagerParam{
    protected $aviso;
    protected $pager;
    
    
    
    /**
     *Constructor
     * @param type $sfActions 
     */
    public function __construct($sfActions) {
        $this->sfActions = $sfActions;
        $this->aviso = new Aviso();
    }
    /**
     *
     * @param sfWebRequest $request
     * @return type Aviso
     */
    public function generar(sfWebRequest $request){
        $paramsArray = null;
        $strParams = null;
        
        $paramsArray = $this->generateArrayParameters($request);
        $strParams = $this->generateStrParameters($paramsArray);

        
        
        $this->pager = $this->generarPager($paramsArray,$strParams);
        //$this->logMessage("paginado : $pager",'info');
//        $this->aviso->setPager($pager);
        
        $avisos = $this->generarAvisos($paramsArray,$strParams);
        //$this->logMessage("Avisos ##### : $avisos",'info');
        $this->aviso->setAvisos($avisos);
        $this->aviso->setCantidadTotal(Doctrine_Core::getTable('Institucion')->getCount($paramsArray));
    }
    protected function generarAvisos($params,$strParams){
        $avisos = null;
        $this->logMessage("params : $strParams",'info');
        $avisos = Doctrine_Core::getTable('Institucion')->getInstituciones($params);
        return $avisos;
    }
   
    protected function generarPager($params,$strParams){
        $cantidadPorPagina = $this->getValueFromUrlParam($params,UrlParameter::cantidadPorPagina);
        $pagina = $this->getValueFromUrlParam($params,UrlParameter::pagina);        
        $pager = new ManagerPaginado($this->sfActions,$pagina, $cantidadPorPagina,5, $params, $strParams);
        $pager->generar();
//        $pager->setPage($this->getValueFromUrlParam($params,UrlParameter::pagina));
//        $pager->init();
        return $pager;
    }
    public function getAviso() {
        return $this->aviso;
    }

    public function setAviso($aviso) {
        $this->aviso = $aviso;
    }
    public function getPager() {
        return $this->pager;
    }

    public function setPager($pager) {
        $this->pager = $pager;
    }



}

?>
